package com.ticket.sass.admin.dto.output.banner;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.ticket.sass.admin.model.KeyInfoModel;
import com.ticket.sass.admin.util.GsonUtil;
import com.ticket.sass.common.entity.tenant.BannerEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ywb
 * @date 2024-04-30 11:04
 */
@Data
@ApiModel
public class BannerListOutput {
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    
    @ApiModelProperty(value = "标题")
    private String title;
    
    @ApiModelProperty(value = "云存储Key")
    private KeyInfoModel keyModel;
    
    @ApiModelProperty(value = "跳转类型：0 不跳转，1 内部页面")
    private Short jumpType;
    
    @ApiModelProperty(value = "跳转配置")
    private Map<String, Object> jumpConfig;
    
    @ApiModelProperty(value = "显示位置：1 首页")
    private List<Short> position;
    
    public BannerListOutput() {
    }
    
    public BannerListOutput(BannerEntity entity) {
        this.id = entity.getId();
        this.title = entity.getTitle();
        this.keyModel = new KeyInfoModel(entity.getKey());
        this.jumpType = entity.getJumpType().getValue();
        this.jumpConfig = StrUtil.isBlankIfStr(entity.getJumpConfig()) ? new HashMap<>() : GsonUtil.getInstance().fromJson(entity.getJumpConfig(), new com.google.gson.reflect.TypeToken<Map<String, Object>>() {}.getType());
//        this.position = entity.getPosition().getValue();
    }
}
